package com.wzh.optional;

import com.wzh.functionalInterface.AutoAddSuffix;
import com.wzh.po.User;

import java.util.ArrayList;
import java.util.Optional;


/**
 * @description:
 * @author: WZH
 * @time: 2021/5/20 8:49
 */

public class Demo {


    public static void main(String[] args) {

    }

//    private static   String add(String s){
//        return s+"后缀";
//    }

    public void toWord(){

        User userZhang = new User("张三", 18, "北京", null);
        User userLi = new User("李四", 15, "南京", null);
        ArrayList<User> list = new ArrayList<>();
        list.add(userLi);
        list.add(userZhang);
        User userWang = new User("王五", 21, "重庆", list);

        String ca = "张三";
        String cb = "李四";
        String cc = "王五";
        String cd = "";
        String ce = null;

        AutoAddSuffix autoAddSuffix =  (String s)->{ return s+"后缀";};


        String value1 = Optional.ofNullable(ca).orElseGet(()->"张三");
        Optional<String> ca1 = Optional.ofNullable(ca);
        ca1.ifPresent((String s)->{
            String s1 = s + "后缀";
            });
        String value2 = Optional.ofNullable(cd).orElse("没有值");
        String value3 = Optional.ofNullable(ce).orElse("没有值");

        System.out.println(value1);
        System.out.println(value2);
        System.out.println(value3);

        Integer i = new Integer(2);
        Optional.ofNullable(i).ifPresent(t -> t = 3);

        int j = 4;
        Optional.ofNullable(i).ifPresent(t -> t = 5);
    }

    public void test(){
        User user = new User("anna@gmail.com");
        String email = Optional.ofNullable(user)
                .map(u -> u.getAddress()).orElse("default@gmail.com");

//        assertEquals(email, user.getEmail());
    }

}
